package com.wpre.orderservice.controller;

import com.wpre.orderservice.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2025-04-08
 * Time: 20:20
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/create")
    public String create() {
        rabbitTemplate.convertAndSend("", "order.create", UUID.randomUUID().toString());
        return "下单成功";
    }

    @RequestMapping("/create2")
    public String create2() {
        OrderInfo info = new OrderInfo();
        info.setId(UUID.randomUUID().toString());
        info.setName("Order1");
//        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        rabbitTemplate.convertAndSend("", "order.create", info);

        return "下单成功";
    }
}
